m = eval(input())
n = eval(input())
i = 1
sum = 0
if n % 7 == 0:
    while i < n:
        if i % 7 != 0:
            sum += 1
        i += 1
    j = sum % m
    if j ==0:
        print (m)
    print(j)
else:
    while i <= n:
        if i % 7 != 0:
            sum += 1
        i += 1
    j = sum % m
    if j ==0:
        print (m)
    print(j)